//
//  HWNewFeatureViewController.m
//  LiGeng微博
//
//  Created by lanou3g on 15/6/17.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "HWNewFeatureViewController.h"

#define HWNewFeatureCount  4

@interface HWNewFeatureViewController ()<UIScrollViewDelegate>
@property(nonatomic,retain)UIScrollView *scrollView;
@property(nonatomic,retain)UIPageControl *pageControl;
@end

@implementation HWNewFeatureViewController

- (void)viewDidLoad {

    [super viewDidLoad];
    
    
    //1.创建一个scrollView
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,            kScreenWidth, kScreenHeight)];
    
    //设置属性
    self.scrollView.contentSize = CGSizeMake(kScreenWidth * 5, kScreenHeight);
    self.scrollView.bounces      = NO;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    
    self.scrollView.delegate = self;
    
    [self.view addSubview:_scrollView];
    
    //2.把图片加到scrollView中
    
    for(int  i = 0 ;i <= 5; i++)
    {
        UIImageView*imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i *kScreenWidth, 0, kScreenWidth, kScreenHeight)];
        
        NSString *str = [NSString stringWithFormat:@"Live%d",i+1];
        
        
        imageView.image = [UIImage imageNamed:str];
        
        
         NSLog(@"----i------%d",i);
        if (i == 4)
        {
            [self  setupLastImageView:imageView];
          
        }
        
        [self.scrollView addSubview:imageView];
     }
    
    UIPageControl *pageControl= [[UIPageControl alloc]initWithFrame:CGRectMake(kScreenWidth*0.5 - kScreenIp6(50), kScreenHeight - 50, kScreenIp6(100),kScreenIp6(30))];
    pageControl.currentPage = 1;
    pageControl.numberOfPages = 5;
    
   pageControl.currentPageIndicatorTintColor = [UIColor greenColor];
    pageControl.pageIndicatorTintColor = [UIColor colorWithRed:189 green:189 blue:189 alpha:1];
    
    [pageControl addTarget:self action:@selector(pageControlAction:) forControlEvents:UIControlEventValueChanged];
    self.pageControl = pageControl;
    [self.view addSubview:_pageControl];
    

}
#pragma mark  pageControll
-(void)pageControlAction:(UIPageControl*)sender
{
    self.scrollView.contentOffset = CGPointMake(sender.currentPage*kScreenWidth, kScreenHeight);
}
#pragma mark  didEnd
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    
    self.pageControl.currentPage = scrollView.contentOffset.x/kScreenWidth;
    
 
}

#pragma mark 最后一张
-(void)setupLastImageView:(UIImageView*)imageView
{
     imageView.userInteractionEnabled = YES;


    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(kScreenWidth/2-kScreenIp6(50), kScreenIp6(545), kScreenIp6(100) ,kScreenIp6(30) );
    
    
    [button setBackgroundImage:[UIImage imageNamed:@"HistoryK3Bg@2x"] forState:UIControlStateNormal];

    
    
    [button setTitle:@"开始" forState:UIControlStateNormal];
    
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
    [imageView  addSubview:button];
    
}

#pragma mark 开始按钮
-(void)startAction:(UIButton *)button
{
    
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    BaseTabBarViewController *baseTVC = [[BaseTabBarViewController alloc] init];
    
    window.rootViewController =baseTVC;
}

@end
